package org.mindrive.system.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ResponseMessage;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration // 标记配置类
@EnableSwagger2 // 开启在线接口文档
public class Swagger2Config {


    @Bean
    public Docket docket1() {
        List<ResponseMessage> responseMessages = new ArrayList<ResponseMessage>();
        responseMessages.add(new ResponseMessageBuilder().code(500).message("系统繁忙！").build());
        responseMessages.add(new ResponseMessageBuilder().code(200).message("成功!").build());
        responseMessages.add(new ResponseMessageBuilder().code(400).message("请求失败").build());
        responseMessages.add(new ResponseMessageBuilder().code(401).message("用户认证失败").build());
        responseMessages.add(new ResponseMessageBuilder().code(402).message("参数不能为空").build());
        responseMessages.add(new ResponseMessageBuilder().code(403).message("参数格式错误").build());
        responseMessages.add(new ResponseMessageBuilder().code(404).message("接口不存在").build());
        responseMessages.add(new ResponseMessageBuilder().code(405).message("未知错误").build());
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).groupName("系统管理").select()
                .apis(RequestHandlerSelectors.basePackage("org.mindrive.system.web.system"))
                .paths(PathSelectors.regex("/.*")).build().globalResponseMessage(RequestMethod.POST, responseMessages);
    }

    @Bean
    public Docket docket2() {
        List<ResponseMessage> responseMessages = new ArrayList<ResponseMessage>();
        responseMessages.add(new ResponseMessageBuilder().code(500).message("系统繁忙！").build());
        responseMessages.add(new ResponseMessageBuilder().code(200).message("成功!").build());
        responseMessages.add(new ResponseMessageBuilder().code(400).message("请求失败").build());
        responseMessages.add(new ResponseMessageBuilder().code(401).message("用户认证失败").build());
        responseMessages.add(new ResponseMessageBuilder().code(402).message("参数不能为空").build());
        responseMessages.add(new ResponseMessageBuilder().code(403).message("参数格式错误").build());
        responseMessages.add(new ResponseMessageBuilder().code(404).message("接口不存在").build());
        responseMessages.add(new ResponseMessageBuilder().code(405).message("未知错误").build());
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).groupName("报表管理").select()
                .apis(RequestHandlerSelectors.basePackage("org.mindrive.system.web.expenses"))
                .paths(PathSelectors.regex("/.*")).build().globalResponseMessage(RequestMethod.POST, responseMessages);
    }

    @Bean
    public Docket docket3() {
        List<ResponseMessage> responseMessages = new ArrayList<ResponseMessage>();
        responseMessages.add(new ResponseMessageBuilder().code(500).message("系统繁忙！").build());
        responseMessages.add(new ResponseMessageBuilder().code(200).message("成功!").build());
        responseMessages.add(new ResponseMessageBuilder().code(400).message("请求失败").build());
        responseMessages.add(new ResponseMessageBuilder().code(401).message("用户认证失败").build());
        responseMessages.add(new ResponseMessageBuilder().code(402).message("参数不能为空").build());
        responseMessages.add(new ResponseMessageBuilder().code(403).message("参数格式错误").build());
        responseMessages.add(new ResponseMessageBuilder().code(404).message("接口不存在").build());
        responseMessages.add(new ResponseMessageBuilder().code(405).message("未知错误").build());
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).groupName("日程管理").select()
                .apis(RequestHandlerSelectors.basePackage("org.mindrive.system.web.schedule"))
                .paths(PathSelectors.regex("/.*")).build().globalResponseMessage(RequestMethod.POST, responseMessages);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("费用填报").description("").contact("mwh").version("1.0").build();
    }

}
